import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== global declare
const { $fn, $http, $Lazy } = window
const $cache 			= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== data
const statusData = [
	{ name:'停用', 		value: '0' },
	{ name:'待校准', 	value: '1' },
	{ name:'通过', 		value: '2' },
]
// ===================================================================== component
class Index extends React.Component{
	state = {
		// 提交表单列表
		formData : [
			{ label: '项目名称',		name: 'kind_id',	disabled: 1,	half:true, type: 'select', required:true,  },
			{ label: '状态',			name: 'status',			half:true, type: 'select', required:true, data: statusData },
			{ label: '执行人',		name: 'checker_uuid', 	half:true, required:true, type:'select' },
			{ label: '上次校准时间',	name: 'last_check_at', 	half:true, ...$fn.table.time, disabled: 1, },
			{ label: '结果',        	name:'remark', 			full:true, required:true, type:'textarea' },
		]
	}
	
	model = {}
	submit = {}
	
	open = ({uuid, device_name}, deviceData)=> {
		
		this.modal.open({ formRef:this.formRef })
		this.submit ={ plan_uuid: uuid }
		const { formData } = this.state
		
		$cache.then( async f => {
			$fn.setRows([formData], 'checker_uuid', await f.getCache( { api: 'employee' } ) )
		})
		
		if(!$fn.hasArray(formData[0].data)){
			$fn.setRow(formData, 'kind_id', deviceData)
			this.setState({ formData })
		}
		
		$http.submit(this,'kd-check-plan/info',{ param:{ uuid } }).then(data=>{
			this.formRef.setValue({...data, operator_at: data.update_at})
		})
	}
	
	render(){
		return FormModal.call(this,{ title:'校准', labelWidth:'s7', width:700, api:'kd-check-plan/check'})
	}
}

export default Index